package com.li.suanfa;

import java.util.Arrays;
import java.util.Random;

/**  
* 类说明   
*  
* @author ****  
* @date 2018年4月1日  新建  
*/
public class ShellSort {
	public static final int SIZE = 10;
	public static void main(String[] args) {
		int[] array = new int[SIZE];
		Random random = new Random();
		for(int i = 0;i < SIZE ;i++){
			array[i] = random.nextInt(100);
		}
		
		System.out.println(Arrays.toString(array));
		shellSort(array,array.length);
		System.out.println(Arrays.toString(array));
	}
	public static void shellSort(int[] a,int n){
		int j = 0;
		int temp = 0;
		while((n/=2) > 0){
			for(int i=n;i<a.length;i++){
				temp = a[i];
				j = i-n;
				while(j>=0 && temp<a[j]){
					a[j+n] = a[j];
					j -= n;
				}
				a[j+n] = temp;
			}
		}
	}
}
  